package com.heima.article.listener;

import com.heima.article.service.IApArticleService;
import com.heima.common.constants.KafkaConstant;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

@Component
@Slf4j
public class TaskListenter {

    @Resource
    private IApArticleService iApArticleService;


    @KafkaListener(topics = KafkaConstant.TOPIC_ARTICLE_UP_OK)
    public void autoTask(ConsumerRecord<String, String> record, Consumer<String,String> consumer) throws TemplateException, IOException {
        //获取数据
        long articleId = Long.parseLong(record.value());
        //发布
        iApArticleService.upArticle(articleId);
    }
}
